package com.wryyyyy.utils;

import java.util.List;

public class FluxFilter {
    public static StringBuilder getFactoryIdFilter(List<String> factoryIds) {
        if (factoryIds.isEmpty()) {
            factoryIds.add("");
        }

        StringBuilder factoryIdFilter = new StringBuilder("  |> filter(fn: (r) => ");

        int i = 0;
        for (String factoryId : factoryIds) {
            if (i != 0) {
                factoryIdFilter.append(" or ");
            }
            factoryIdFilter.append("r[\"factory_id\"] == \"").append(factoryId).append("\"");
            i++;
        }
        factoryIdFilter.append(")");

        return factoryIdFilter;
    }

    public static StringBuilder getCountryIdFilter(List<String> countryIds) {
        if (countryIds.isEmpty()) {
            countryIds.add("");
        }

        StringBuilder countryIdFilter = new StringBuilder("  |> filter(fn: (r) => ");

        int i = 0;
        for (String  countryId: countryIds) {
            if (i != 0) {
                countryIdFilter.append(" or ");
            }
            countryIdFilter.append("r[\"country_id\"] == \"").append(countryId).append("\"");
            i++;
        }
        countryIdFilter.append(")");

        return countryIdFilter;
    }
}
